<template>
  <div>
    <follow-user-item
      v-for="u in users"
      :key="u.id"
      :user="u"
    ></follow-user-item>
    <el-skeleton :loading="loading" :rows="6" animated />
    <el-empty v-if="page.total == 0 && !loading" description="空空如也~"></el-empty>
  </div>
</template>

<script>
import FollowUserItem from "./FollowUserItem.vue";
import PageMixin from "@/mixins/PageMixin";
import userApi from "@/axios/userApi";
export default {
  components: { FollowUserItem },
  mixins: [PageMixin],
  data() {
    return {
      users: [],
    };
  },
  methods: {
    fetchData() {
      if (this.$route.name == "followings")
        userApi
          .getFollowingList({
            current: this.page.current,
            size: this.page.size,
            userId:this.$route.params.userId
          })
          .then(({ data }) => {
            if (data.code === this.$status.SUCCESS_CODE) {
              this.users = this.users.concat(data.data.records.map(v=>v.followedUser));
              this.page.current = data.data.current;
              this.page.total = data.data.total;
              this.page.pages = data.data.pages;
              //关闭加载动画
              this.loading = false;
            } else this.$message.error("获取数据出错");
          });
      else
        userApi
          .getFansList({ current: this.page.current, size: this.page.size,userId:this.$route.params.userId })
          .then(({ data }) => {
            if (data.code === this.$status.SUCCESS_CODE) {
              this.users = this.users.concat(data.data.records.map(v=>v.followedUser));
              this.page.current = data.data.current;
              this.page.total = data.data.total;
              this.page.pages = data.data.pages;
              //关闭加载动画
              this.loading = false;
            } else this.$message.error("获取数据出错");
          });
    },
    load() {
      this.page.current++;
      this.fetchData();
    },
    
  },
  created() {
      this.fetchData();
    }
};
</script>

<style>
</style>